<template>
  <div class="register-container">
    <div class="register-content">
      <el-card class="register-card" :body-style="{ padding: '40px' }">
        <div class="logo-container">
          <div class="logo">KG</div>
        </div>
        <h2>创建账号</h2>
        <p class="subtitle">加入威胁情报图谱构建和可信度评估系统</p>
        <el-form :model="form" @submit.prevent="handleSubmit" class="register-form">
          <el-form-item>
            <el-input
              v-model="form.username"
              placeholder="用户名"
              :prefix-icon="ElIconUser"
              class="custom-input"
            />
          </el-form-item>
          <el-form-item>
            <el-input
              v-model="form.email"
              type="email"
              placeholder="邮箱"
              :prefix-icon="ElIconMessage"
              class="custom-input"
            />
          </el-form-item>
          <el-form-item>
            <el-input
              v-model="form.password"
              type="password"
              placeholder="密码"
              :prefix-icon="ElIconLock"
              show-password
              class="custom-input"
            />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" native-type="submit" :loading="loading" class="submit-btn" round>
              注册
            </el-button>
          </el-form-item>
          <div class="login-link">
            已有账号？
            <router-link to="/login" class="accent-link">立即登录</router-link>
          </div>
        </el-form>
      </el-card>
    </div>
    <div class="background-shapes">
      <div class="shape shape-1"></div>
      <div class="shape shape-2"></div>
      <div class="shape shape-3"></div>
      <div class="shape shape-4"></div>
      <div class="shape shape-5"></div>
      <div class="shape shape-6"></div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import { useAuthStore } from '../stores/auth'
import { ElMessage } from 'element-plus'
import { Message as ElIconMessage, Lock as ElIconLock, User as ElIconUser } from '@element-plus/icons-vue'

const router = useRouter()
const authStore = useAuthStore()

const form = ref({
  username: '',
  email: '',
  password: ''
})

const loading = ref(false)

const handleSubmit = async () => {
  if (!form.value.username || !form.value.email || !form.value.password) {
    ElMessage.error('请填写所有字段')
    return
  }

  loading.value = true
  try {
    await authStore.register(
      form.value.username,
      form.value.email,
      form.value.password
    )
    ElMessage.success('注册成功，请登录')
    router.push('/login')
  } catch (error) {
    ElMessage.error(error.response?.data?.detail || '注册失败')
  } finally {
    loading.value = false
  }
}
</script>

<style scoped>
.register-container {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #f5f7fa 0%, #e4e8f0 100%);
  position: relative;
  overflow: hidden;
}

.register-content {
  position: relative;
  z-index: 10;
  width: 100%;
  max-width: 90%;
  padding: 20px;
  transition: all 0.3s ease;
}

.register-card {
  border-radius: 16px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
  background-color: white;
  transition: all 0.3s ease;
  overflow: hidden;
}

.register-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
}

.logo-container {
  display: flex;
  justify-content: center;
  margin-bottom: 25px;
}

.logo {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: linear-gradient(135deg, #409eff, #67c23a);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  font-weight: bold;
  box-shadow: 0 8px 16px rgba(64, 158, 255, 0.3);
  transition: all 0.3s ease;
}

.logo:hover {
  transform: rotate(5deg) scale(1.05);
}

h2 {
  text-align: center;
  margin-bottom: 10px;
  color: #303133;
  font-size: 32px;
  font-weight: 600;
}

.subtitle {
  text-align: center;
  color: #909399;
  margin-bottom: 35px;
  font-size: 16px;
}

.register-form {
  margin-top: 20px;
}

.custom-input :deep(.el-input__inner) {
  border-radius: 8px;
  padding: 14px 16px;
  height: 50px;
  font-size: 16px;
  border: 1px solid #dcdfe6;
  transition: all 0.3s;
}

.custom-input :deep(.el-input__inner:focus) {
  border-color: #409eff;
  box-shadow: 0 0 0 2px rgba(64, 158, 255, 0.2);
}

.custom-input :deep(.el-input__prefix) {
  font-size: 18px;
  left: 12px;
}

.submit-btn {
  width: 100%;
  padding: 16px;
  font-size: 18px;
  margin-top: 20px;
  background: linear-gradient(to right, #409eff, #67c23a);
  border: none;
  transition: all 0.3s;
  height: 55px;
}

.submit-btn:hover {
  opacity: 0.9;
  transform: translateY(-2px);
  box-shadow: 0 8px 16px rgba(64, 158, 255, 0.3);
}

.login-link {
  text-align: center;
  margin-top: 25px;
  font-size: 16px;
  color: #606266;
}

.accent-link {
  color: #409eff;
  text-decoration: none;
  font-weight: 500;
  transition: all 0.3s;
}

.accent-link:hover {
  color: #67c23a;
  text-decoration: underline;
}

.background-shapes .shape {
  position: absolute;
  border-radius: 50%;
  background: linear-gradient(45deg, rgba(64, 158, 255, 0.1), rgba(103, 194, 58, 0.1));
  animation: float 6s infinite ease-in-out;
}

.shape-1 {
  width: 400px;
  height: 400px;
  top: -150px;
  right: -100px;
  animation-delay: 0s;
}

.shape-2 {
  width: 300px;
  height: 300px;
  bottom: -100px;
  left: -50px;
  animation-delay: 1s;
}

.shape-3 {
  width: 200px;
  height: 200px;
  bottom: 30%;
  right: 10%;
  animation-delay: 2s;
}

.shape-4 {
  width: 150px;
  height: 150px;
  top: 20%;
  left: 10%;
  animation-delay: 3s;
}

.shape-5 {
  width: 100px;
  height: 100px;
  top: 40%;
  right: 30%;
  animation-delay: 4s;
}

.shape-6 {
  width: 120px;
  height: 120px;
  bottom: 20%;
  right: 20%;
  animation-delay: 5s;
}

@keyframes float {
  0% { transform: translateY(0px) rotate(0deg); }
  50% { transform: translateY(-20px) rotate(5deg); }
  100% { transform: translateY(0px) rotate(0deg); }
}

/* Responsive Design */
@media (min-width: 768px) {
  .register-content {
    max-width: 500px;
  }
  
  .register-card {
    padding: 20px;
  }
  
  h2 {
    font-size: 36px;
  }
  
  .subtitle {
    font-size: 18px;
  }
}

@media (min-width: 1200px) {
  .register-content {
    max-width: 550px;
  }
  
  .register-card {
    padding: 30px;
  }
}
</style> 